{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Discrete Bayes Animations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>\n",
       "@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
       "@import url('http://fonts.googleapis.com/css?family=Lora');\n",
       "\n",
       "//@import url('http://fonts.googleapis.com/css?family=Open+Sans');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Vollkorn');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Karla');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Poppins');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Arimo');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Roboto');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Lato');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Domine');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Chivo');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Cardo');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Arvo');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Crimson+Text');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Ubuntu');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Fontin');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Raleway');\n",
       "//@import url('http://fonts.googleapis.com/css?family=Merriweather');\n",
       "\n",
       "\n",
       ".CodeMirror pre {\n",
       "    font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
       "}\n",
       "    div.cell{\n",
       "        //width: 950px;\n",
       "        margin-left: 0% !important;\n",
       "        margin-right: auto;\n",
       "    }\n",
       "    div.text_cell_render{\n",
       "        font-family: 'Lora';\n",
       "        //font-family: 'Open Sans';\n",
       "        //font-family: 'Karla',verdana,arial,sans-serif;\n",
       "        //font-family: 'Roboto',verdana,arial,sans-serif;\n",
       "        //font-family: 'Lato',verdana,arial,sans-serif;\n",
       "        //font-family: 'Domine',verdana,arial,sans-serif;\n",
       "        //font-family: 'Chivo',verdana,arial,sans-serif;\n",
       "        //font-family: 'Cardo',verdana,arial,sans-serif;\n",
       "        //font-family: 'Arvo',verdana,arial,sans-serif;\n",
       "        //font-family: 'Poppins',verdana,arial,sans-serif;\n",
       "        //font-family: 'Ubuntu',verdana,arial,sans-serif;\n",
       "        //font-family: 'Fontin',verdana,arial,sans-serif;\n",
       "        //font-family: 'Raleway',verdana,arial,sans-serif;\n",
       "        //font-family: 'Merriweather',verdana,arial,sans-serif;\n",
       "        //font-family: 'Crimson Text', verdana,arial,sans-serif;\n",
       "        //font-family: verdana,arial,sans-serif;\n",
       "        //font-family: arial,sans-serif;\n",
       "        line-height: 125%;\n",
       "        font-size: 130%;\n",
       "        text-align: justify;\n",
       "        text-justify:inter-word;\n",
       "    }\n",
       "    div.text_cell code {\n",
       "        background: transparent;\n",
       "        color: #000000;\n",
       "        font-weight: 400;\n",
       "        font-size: 12pt;\n",
       "        //font-style: bold;\n",
       "        font-family:  'Source Code Pro', Consolas, monocco, monospace;\n",
       "   }\n",
       "    h1 {\n",
       "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "\t}\n",
       "\n",
       "    div.input_area {\n",
       "        background: #F6F6F9;\n",
       "        border: 1px solid #586e75;\n",
       "    }\n",
       "\n",
       "    .text_cell_render h1 {\n",
       "        font-weight: 200;\n",
       "        font-size: 30pt;\n",
       "        line-height: 100%;\n",
       "        color:#c76c0c;\n",
       "        margin-bottom: 0.5em;\n",
       "        margin-top: 1em;\n",
       "        display: block;\n",
       "        white-space: wrap;\n",
       "        text-align: left;\n",
       "    }\n",
       "    h2 {\n",
       "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "        text-align: left;\n",
       "    }\n",
       "    .text_cell_render h2 {\n",
       "        font-weight: 200;\n",
       "        font-size: 16pt;\n",
       "        font-style: italic;\n",
       "        line-height: 100%;\n",
       "        color:#c76c0c;\n",
       "        margin-bottom: 0.5em;\n",
       "        margin-top: 1.5em;\n",
       "        display: block;\n",
       "        white-space: wrap;\n",
       "        text-align: left;\n",
       "    }\n",
       "    h3 {\n",
       "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "    }\n",
       "    .text_cell_render h3 {\n",
       "        font-weight: 200;\n",
       "        font-size: 14pt;\n",
       "        line-height: 100%;\n",
       "        color:#d77c0c;\n",
       "        margin-bottom: 0.5em;\n",
       "        margin-top: 2em;\n",
       "        display: block;\n",
       "        white-space: wrap;\n",
       "        text-align: left;\n",
       "    }\n",
       "    h4 {\n",
       "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "    }\n",
       "    .text_cell_render h4 {\n",
       "        font-weight: 100;\n",
       "        font-size: 14pt;\n",
       "        color:#d77c0c;\n",
       "        margin-bottom: 0.5em;\n",
       "        margin-top: 0.5em;\n",
       "        display: block;\n",
       "        white-space: nowrap;\n",
       "    }\n",
       "    h5 {\n",
       "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "    }\n",
       "\n",
       "    .text_cell_render h5 {\n",
       "        font-weight: 200;\n",
       "        font-style: normal;\n",
       "        color: #1d3b84;\n",
       "        font-size: 16pt;\n",
       "        margin-bottom: 0em;\n",
       "        margin-top: 0.5em;\n",
       "        display: block;\n",
       "        white-space: nowrap;\n",
       "    }\n",
       "    div.output_subarea.output_text.output_pyout {\n",
       "        overflow-x: auto;\n",
       "        overflow-y: scroll;\n",
       "        max-height: 50000px;\n",
       "    }\n",
       "    div.output_subarea.output_stream.output_stdout.output_text {\n",
       "        overflow-x: auto;\n",
       "        overflow-y: scroll;\n",
       "        max-height: 50000px;\n",
       "    }\n",
       "    div.output_wrapper{\n",
       "        margin-top:0.2em;\n",
       "        margin-bottom:0.2em;\n",
       "}\n",
       "\n",
       "    code{\n",
       "        font-size: 6pt;\n",
       "\n",
       "    }\n",
       "    .rendered_html code{\n",
       "    background-color: transparent;\n",
       "    }\n",
       "    ul{\n",
       "        margin: 2em;\n",
       "    }\n",
       "    ul li{\n",
       "        padding-left: 0.5em;\n",
       "        margin-bottom: 0.5em;\n",
       "        margin-top: 0.5em;\n",
       "    }\n",
       "    ul li li{\n",
       "        padding-left: 0.2em;\n",
       "        margin-bottom: 0.2em;\n",
       "        margin-top: 0.2em;\n",
       "    }\n",
       "    ol{\n",
       "        margin: 2em;\n",
       "    }\n",
       "    ol li{\n",
       "        padding-left: 0.5em;\n",
       "        margin-bottom: 0.5em;\n",
       "        margin-top: 0.5em;\n",
       "    }\n",
       "    ul li{\n",
       "        padding-left: 0.5em;\n",
       "        margin-bottom: 0.5em;\n",
       "        margin-top: 0.2em;\n",
       "    }\n",
       "    a:link{\n",
       "       color:#447adb;\n",
       "    }\n",
       "    a:visited{\n",
       "       color: #1d3b84;\n",
       "    }\n",
       "    a:hover{\n",
       "       color: #1d3b84;\n",
       "    }\n",
       "    a:focus{\n",
       "       color:#447adb;\n",
       "    }\n",
       "    a:active{\n",
       "       font-weight: bold;\n",
       "       color:#447adb;\n",
       "    }\n",
       "    .rendered_html :link {\n",
       "       text-decoration: underline;\n",
       "    }\n",
       "    .rendered_html :hover {\n",
       "       text-decoration: none;\n",
       "    }\n",
       "    .rendered_html :visited {\n",
       "      text-decoration: none;\n",
       "    }\n",
       "    .rendered_html :focus {\n",
       "      text-decoration: none;\n",
       "    }\n",
       "    .rendered_html :active {\n",
       "      text-decoration: none;\n",
       "    }\n",
       "    .warning{\n",
       "        color: rgb( 240, 20, 20 )\n",
       "    }\n",
       "    hr {\n",
       "      color: #f3f3f3;\n",
       "      background-color: #f3f3f3;\n",
       "      height: 1px;\n",
       "    }\n",
       "    blockquote{\n",
       "      display:block;\n",
       "      background: #fcfcfc;\n",
       "      border-left: 5px solid #c76c0c;\n",
       "      font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "      width:680px;\n",
       "      padding: 10px 10px 10px 10px;\n",
       "      text-align:justify;\n",
       "      text-justify:inter-word;\n",
       "      }\n",
       "      blockquote p {\n",
       "        margin-bottom: 0;\n",
       "        line-height: 125%;\n",
       "        font-size: 100%;\n",
       "      }\n",
       "</style>\n",
       "<script>\n",
       "    MathJax.Hub.Config({\n",
       "                        TeX: {\n",
       "                           extensions: [\"AMSmath.js\"],\n",
       "                           equationNumbers: { autoNumber: \"AMS\", useLabelIds: true}\n",
       "                           },\n",
       "                tex2jax: {\n",
       "                    inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
       "                    displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
       "                },\n",
       "                displayAlign: 'center', // Change this to 'center' to center equations.\n",
       "                \"HTML-CSS\": {\n",
       "                    scale:95,\n",
       "                        availableFonts: [],\n",
       "                        preferredFont:null,\n",
       "                        webFont: \"TeX\",\n",
       "                    styles: {'.MathJax_Display': {\"margin\": 4}}\n",
       "                }\n",
       "        });\n",
       "</script>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from __future__ import division, print_function\n",
    "import matplotlib.pyplot as plt\n",
    "import sys\n",
    "sys.path.insert(0,'..') # allow us to format the book\n",
    "sys.path.insert(0,'../code') \n",
    "import book_format\n",
    "book_format.load_style(directory='..')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook creates the animations for the Discrete Bayesian filters chapter. It is not really intended to be a readable part of the book, but of course you are free to look at the source code, and even modify it. However, if you are interested in running your own animations, I'll point you to the examples subdirectory of the book, which contains a number of python scripts that you can run and modify from an IDE or the command line. This module saves the animations to GIF files, which is quite slow and not very interactive. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from matplotlib import animation\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from book_plots import bar_plot\n",
    "%matplotlib inline\n",
    "\n",
    "# the predict algorithm of the discrete bayesian filter\n",
    "def predict(pos, move, p_correct, p_under, p_over):\n",
    "    n = len(pos)\n",
    "    result = np.array(pos, dtype=float)\n",
    "    for i in range(n):\n",
    "                result[i] =  \\\n",
    "            pos[(i-move) % n]   * p_correct + \\\n",
    "            pos[(i-move-1) % n] * p_over + \\\n",
    "            pos[(i-move+1) % n] * p_under          \n",
    "    return result\n",
    "\n",
    "\n",
    "def normalize(p):\n",
    "    s = sum(p)\n",
    "    for i in range (len(p)):\n",
    "        p[i] = p[i] / s\n",
    "        \n",
    "# the update algorithm of the discrete bayesian filter\n",
    "def update(pos, measure, p_hit, p_miss):\n",
    "    q = np.array(pos, dtype=float)\n",
    "    for i in range(len(hallway)):\n",
    "        if hallway[i] == measure:\n",
    "            q[i] = pos[i] * p_hit\n",
    "        else:\n",
    "            q[i] = pos[i] * p_miss\n",
    "    normalize(q)\n",
    "    return q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:\\Anaconda3\\lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'imagemagick'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import matplotlib\n",
    "# make sure our matplotlibrc has been edited to use imagemagick\n",
    "print(matplotlib.matplotlib_fname())\n",
    "matplotlib.rcParams['animation.writer']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAEKCAYAAAAPVd6lAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEcNJREFUeJzt3X2QXXV9x/H3JksihAWCroqCIqjf0VHREYaQRkCG1CpQ\nY9U/KFiJohZbdaTVaXSsU5xapwrjU6mhQQQbH4PRKhpaLahJKba01FD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uiPgy8DfA1/qQ4VeqW3g8OzOv7cPwW4DB6p380cBDfcjwbOAbANW7\ngWf1YtC6F/mUtwfodYjMXE/jrVrfZOaezPxFRAwBXwTe3ccs+yPiU8BHgLW9Hj8iLgF+mpl/R+P6\nhX7ZA3wwM18CXAas7cPz83E0rut4VZXhMz0ef7JVwJ/0aewHgKcBPwJWAx/tQ4Y7gfPhVxdQPqn6\nwzKn6l7ku4ChpumJe7wckiLiBODvgesz8/P9zJKZlwDPBNZExOE9Hn4lsDwibgGeD9xQHS/vtS1U\nf8gycytwP3BcjzPcD9ycmWPVHuDeiJjdDTsOUkQcDTwzM7/dj/GBtwMbMjNovFu6oTpm3UufBHZH\nxHeAlwN3ZOacX6xT9yKf6fYA/dC3vb+IeAJwM/DOzLy+jzkurk6uQeME9D4aJz17JjPPqo7HvpjG\nHtDvZOZPe5mh8jrgSoCIeBKNnY6f9DjDRuA3mjIcQaPc++FM4Ft9GhtgBwfewf+cxoc5en2LydOA\nb1XnstYBPflwRq0/tQKsp7HntamaXtnPMDTOyPfLKuAY4D0R8cdVlpdm5oM9zvEl4LqI+DaN58/b\n+pChWT//n1xL49/iuzT+mL2u1+8YM/OmiHhRRHyPxo7Gm3uxBziNoEfFNY0PA5+s9oYPA1Zl5i97\nnGEr8L6IeDeN80c9OQHuJfqSVLi6H1qRJLVgkUtS4SxySSqcRS5JhbPIJalwFrkkFc4il6TCWeSS\nVLj/AxjKbhgNuTcFAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x17c12128b38>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAC2CAYAAADOWmoIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAD/BJREFUeJzt3X2QXXV9x/H3JguRxAWirBWrAj7wHZ3StBoE0ghCTa08\nVHzoOIy0EgUtttbRVqfRWlsdH6YIU6tSwCB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ekM/PzEfHciPg61Qei183Vp9cugjl8M+zhH4CP1p/uDwDWZeYvG850O/CuiHgb\n1XnEOfuChfeqkiQVmQ+HqiRJLWJxSJKKWBySpCIWhySpiMUhSSpicUiSilgckqQi/w9XcZj+Xbo+\nZAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x17c10f16518>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from gif_animate import animate\n",
    "\n",
    "pos = [1.0,0,0,0,0,0,0,0,0,0]\n",
    "def bar_animate(nframe):\n",
    "    global pos\n",
    "    plt.cla()\n",
    "    bar_plot(pos)\n",
    "    plt.title('Step {}'.format(nframe + 1))\n",
    "    pos = predict(pos, 1, .8, .1, .1)\n",
    "\n",
    "for i in range(10):\n",
    "    bar_animate(i)\n",
    "\n",
    "fig = plt.figure(figsize=(6.5, 2.5))\n",
    "animate('02_no_info.gif', bar_animate, fig=fig, frames=75, interval=75);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"02_no_info.gif\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "pos = np.array([.1]*10)\n",
    "hallway = np.array([1, 1, 0, 0, 0, 0, 0, 0, 1, 0])\n",
    "\n",
    "def bar_animate(nframe):\n",
    "    global pos\n",
    "    #if nframe == 0:\n",
    "    #   return\n",
    "\n",
    "    bar_plot(pos, ylim=(0,1.0))\n",
    "    plt.title('Step {}'.format(nframe + 1))\n",
    "    if nframe % 2 == 0:\n",
    "        pos = predict(pos, 1, .9, .05, .05)\n",
    "    else:\n",
    "        x = int((nframe/2) % len(hallway))\n",
    "        z = hallway[x]\n",
    "        pos = update(pos, z, .9, .2)\n",
    "        \n",
    "\n",
    "fig = plt.figure(figsize=(6.5, 2.5))\n",
    "animate('02_simulate.gif', bar_animate, fig=fig, frames=40, interval=85);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " <img src=\"02_simulate.gif\">"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
